package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompOsiItem;
import com.ruoyi.womp.service.IWompOsiItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检项目Controller
 * 
 * @author mzz
 * @date 2023-05-11
 */
@Controller
@RequestMapping("/womp/osiItem")
public class WompOsiItemController extends BaseController
{
    private String prefix = "womp/osiItem";

    @Autowired
    private IWompOsiItemService wompOsiItemService;

    @RequiresPermissions("womp:osiItem:view")
    @GetMapping()
    public String osiItem()
    {
        return prefix + "/osiItem";
    }

    /**
     * 查询巡检项目列表
     */
    @RequiresPermissions("womp:osiItem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompOsiItem wompOsiItem)
    {
        startPage();
        List<WompOsiItem> list = wompOsiItemService.selectWompOsiItemList(wompOsiItem);
        return getDataTable(list);
    }

    /**
     * 导出巡检项目列表
     */
    @RequiresPermissions("womp:osiItem:export")
    @Log(title = "巡检项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompOsiItem wompOsiItem)
    {
        List<WompOsiItem> list = wompOsiItemService.selectWompOsiItemList(wompOsiItem);
        ExcelUtil<WompOsiItem> util = new ExcelUtil<WompOsiItem>(WompOsiItem.class);
        return util.exportExcel(list, "巡检项目数据");
    }

    /**
     * 新增巡检项目
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存巡检项目
     */
    @RequiresPermissions("womp:osiItem:add")
    @Log(title = "巡检项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompOsiItem wompOsiItem)
    {
        return toAjax(wompOsiItemService.insertWompOsiItem(wompOsiItem));
    }

    /**
     * 修改巡检项目
     */
    @RequiresPermissions("womp:osiItem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WompOsiItem wompOsiItem = wompOsiItemService.selectWompOsiItemById(id);
        mmap.put("wompOsiItem", wompOsiItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存巡检项目
     */
    @RequiresPermissions("womp:osiItem:edit")
    @Log(title = "巡检项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompOsiItem wompOsiItem)
    {
        return toAjax(wompOsiItemService.updateWompOsiItem(wompOsiItem));
    }

    /**
     * 删除巡检项目
     */
    @RequiresPermissions("womp:osiItem:remove")
    @Log(title = "巡检项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompOsiItemService.deleteWompOsiItemByIds(ids));
    }
}
